package com.shuoyue.ycgk.views.dialog.common;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.utils.MyRichTextHelper;
import com.zzhoujay.richtext.RichText;


/**
 * 提示框Dialog
 * Created by Forty'7 on 2019/8/17
 */

public class HintDialog extends Dialog {
    private Context mContext;
    private TextView tvTitel;
    private TextView tvContent;
    private TextView tvOk;

    public HintDialog(@NonNull Context context, String title, String content) {
        this(context, title, content, Gravity.CENTER);
    }

    public HintDialog(@NonNull Context context, String title, String content, int contentGravity) {
        super(context, R.style.dialog);
        this.mContext = context;
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_hint);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        tvTitel = findViewById(R.id.tv_title);
        tvContent = findViewById(R.id.tv_content);
        tvOk = findViewById(R.id.tv_ok);

        tvTitel.setText(title);
        if (content != null) {
            MyRichTextHelper.showRich(mContext, content, tvContent);
        }
//            tvContent.setText(content);
        if (TextUtils.isEmpty(title)) {
            tvTitel.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(content)) {
            tvContent.setVisibility(View.GONE);
        }
        if (contentGravity != Gravity.LEFT) {
            tvContent.setGravity(contentGravity);
        }
        tvOk.setOnClickListener(v -> dismiss());


    }

    public void setButtonText(String right) {
        if (tvOk != null && !TextUtils.isEmpty(right)) {
            tvOk.setText(right);
        }
    }

    public void setOkListener(View.OnClickListener listener) {
        if (tvOk != null) tvOk.setOnClickListener(listener);
    }

}
